package com.ibiaoke.order.dao;


import com.google.common.collect.Lists;
import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.order.entity.OrderGoods;
import com.ibiaoke.order.entity.OrderGoodsExample;
import com.ibiaoke.order.mapper.OrderGoodsMapper;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * Created by huhaichao on 2017/6/8.
 */
@Repository
public class OrderGoodsDao extends BaseDao<OrderGoods, OrderGoodsExample, Integer, OrderGoodsMapper> {

    @Autowired
    private OrderGoodsMapper orderGoodsMapper;


    @Override
    public OrderGoodsMapper getMapper() {
        return orderGoodsMapper;
    }


    /**
     * 根据订单查询订单商品
     * @param orderId
     * @return
     */
    public List<OrderGoods> listOrderGoods(Integer orderId) {
        OrderGoodsExample example = new OrderGoodsExample();
        example.createCriteria().andOrderIdEqualTo(orderId);
        return orderGoodsMapper.selectByExample(example);
    }

    /**
     * 批量保存订单商品
     * @param orderGoodsList
     */
    public void batchInsert(List<OrderGoods> orderGoodsList) {
        orderGoodsList.forEach(orderGoods -> insertSelective(orderGoods));
    }

    public List<OrderGoods> listOrderGoods(List<Integer> orderIds) {
        if(CollectionUtils.isEmpty(orderIds)){
            return Lists.newArrayList();
        }
        OrderGoodsExample example = new OrderGoodsExample();
        example.createCriteria().andOrderIdIn(orderIds);
        return orderGoodsMapper.selectByExample(example);
    }

}
